

import  logging.handlers

def init_log_config(filename, when='midnight', interval=1, backup_count=7):
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    st = logging.StreamHandler()
    fh = logging.handlers.TimedRotatingFileHandler(filename,
                                                   when=when,
                                                   interval=interval,
                                                   backupCount=backup_count,
                                                   encoding='utf-8')
    fmt = "%(asctime)s %(levelname)s [%(filename)s(%(funcName)s:%(lineno)d)] - %(message)s"
    formatter = logging.Formatter(fmt)
    st.setFormatter(formatter)
    fh.setFormatter(formatter)
    logger.addHandler(st)
    logger.addHandler(fh)

if __name__ == '__main__':
    init_log_config('sky.log')
    logging.info('测试打印信息')
    logging.warning('测试打印信息')